//
//  LCFilesListCell.m
//  LongChain
//
//  Created by FengZi on 2018/4/24.
//  Copyright © 2018年 FengZi. All rights reserved.
//

#import "LCFilesListCell.h"

@implementation LCFilesListCell

- (void)lc_updateFilesListCellWithParameter:(LCFileModel *)parameter enableSelected:(BOOL)enable{
    
    self.model = parameter;
    NSString *imageURL = [NSString stringWithFormat:@"%@%@",BASEURL,parameter.thumbnail];
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:nil options:SDWebImageRetryFailed];
    
    WS(weakSelf);
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        weakSelf.model.image = image;
    }];
    
    self.stateButton.hidden = !enable;
}

- (IBAction)chooseImage:(UIButton *)sender {
    
    NSString *stateImage = self.model.fileSelectedState ? @"list_ic_circle_n" : @"list_ic_circle_h";
    [self.stateButton setImage:[UIImage imageNamed:stateImage] forState:UIControlStateNormal];
    [self.stateButton setImage:[UIImage imageNamed:stateImage] forState:UIControlStateSelected];
    self.model.fileSelectedState = !self.model.fileSelectedState;
    if (self.selectedHandler) {
        self.selectedHandler(self.model);
    }
    
}


@end
